{% extends "base.html" %}

{% block content %}
<div class="card">
    <div class="card-header">
        <h3 class="card-title">离职员工列表</h3>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>姓名</th>
                        <th>身份证号</th>
                        <th>手机号</th>
                        <th>部门</th>
                        <th>职位</th>
                        <th>入职日期</th>
                        <th>离职日期</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for employee in employees %}
                    <tr>
                        <td>{{ employee.name }}</td>
                        <td>{{ employee.id_card }}</td>
                        <td>{{ employee.phone }}</td>
                        <td>{{ employee.department }}</td>
                        <td>{{ employee.position }}</td>
                        <td>
                            {% if employee.hire_date %}
                                {% if employee.hire_date is string %}
                                    {{ employee.hire_date }}
                                {% else %}
                                    {{ employee.hire_date.strftime('%Y-%m-%d') }}
                                {% endif %}
                            {% else %}
                                -
                            {% endif %}
                        </td>
                        <td>
                            {% if employee.resign_date %}
                                {% if employee.resign_date is string %}
                                    {{ employee.resign_date }}
                                {% else %}
                                    {{ employee.resign_date.strftime('%Y-%m-%d') }}
                                {% endif %}
                            {% else %}
                                -
                            {% endif %}
                        </td>
                        <td>
                            <a href="{{ url_for('employee.resigned_detail', id=employee.id) }}" class="btn btn-info btn-sm">查看</a>
                            <button type="button" class="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#deleteModal{{ employee.id }}">
                                删除
                            </button>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

{% for employee in employees %}
<!-- 删除确认模态框 -->
<div class="modal fade" id="deleteModal{{ employee.id }}" tabindex="-1" aria-labelledby="deleteModalLabel{{ employee.id }}" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="deleteModalLabel{{ employee.id }}">确认删除</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                确定要删除离职员工 {{ employee.name }} 吗？此操作不可恢复。
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <a href="{{ url_for('employee.delete_resigned_employee', id=employee.id) }}" class="btn btn-danger">确认删除</a>
            </div>
        </div>
    </div>
</div>
{% endfor %}
{% endblock %} 